package cn.yuanqiao.web.controller.archive.storeRoom;

import cn.yuanqiao.archive.storeRoom.domain.PersonnelEntryExit;
import cn.yuanqiao.archive.storeRoom.domain.Storeroom;
import cn.yuanqiao.archive.storeRoom.service.IPersonnelEntryExitService;
import cn.yuanqiao.archive.storeRoom.service.IStoreroomService;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 人员出入库Controller
 * 
 * @author xy
 * @date 2023-06-19
 */
@RestController
@RequestMapping("/archive/personnelEntryExit")
public class PersonnelEntryExitController extends BaseController
{
    @Autowired
    private IPersonnelEntryExitService personnelEntryExitService;

    @Autowired
    private IStoreroomService storeroomService;

    /**
     * 查询人员出入库列表
     */

    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:PersonnelAccess:list')")
    @GetMapping("/list")
    public TableDataInfo list(PersonnelEntryExit personnelEntryExit)
    {
        startPage();
        List<PersonnelEntryExit> list = personnelEntryExitService.selectPersonnelEntryExitList(personnelEntryExit);
        return getDataTable(list);
    }

    /**
     * 导出人员出入库列表
     */



    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:PersonnelAccess:export')")
    @Log(title = "人员出入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PersonnelEntryExit personnelEntryExit)
    {
        List<PersonnelEntryExit> list = personnelEntryExitService.selectPersonnelEntryExitList(personnelEntryExit);
        ExcelUtil<PersonnelEntryExit> util = new ExcelUtil<PersonnelEntryExit>(PersonnelEntryExit.class);
        util.exportExcel(response, list, "人员出入库数据");
    }

    /**
     * 获取人员出入库详细信息
     */

/*
    @PreAuthorize("@ss.hasPermi('storeroom:personnelEntryExit:query')")
*/
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:PersonnelAccess:detail')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(personnelEntryExitService.selectPersonnelEntryExitByID(id));
    }

    /**
     * 新增人员出入库
     */
/*
    @PreAuthorize("@ss.hasPermi('storeroom:personnelEntryExit:add')")
*/
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:PersonnelAccess:add')")
    @Log(title = "人员出入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PersonnelEntryExit personnelEntryExit)
    {
        return toAjax(personnelEntryExitService.insertPersonnelEntryExit(personnelEntryExit));
    }

    /**
     * 修改人员出入库
     */

/*
    @PreAuthorize("@ss.hasPermi('storeroom:personnelEntryExit:edit')")
*/
    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:PersonnelAccess:edit')")
    @Log(title = "人员出入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PersonnelEntryExit personnelEntryExit)
    {
        return toAjax(personnelEntryExitService.updatePersonnelEntryExit(personnelEntryExit));
    }

    /**
     * 删除人员出入库
     */


    @PreAuthorize("@ss.hasPermi('archive:warehouseManagement:PersonnelAccess:delete')")
    @Log(title = "人员出入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(personnelEntryExitService.deletePersonnelEntryExitByIDs(ids));
    }


    @GetMapping("/storeList")
    public TableDataInfo list(Storeroom storeroom)
    {
        /*startPage();*/
        List<Storeroom> list = storeroomService.selectStoreroomList(storeroom);
        return getDataTable(list);
    }
}
